# coding: utf8
"""
工具杂项
:author: Tony 2015/7/12
"""
__author__ = 'Tony'


def transform_model_to_proxy(origin, proxy_class):
	"""
	将原model对象转换指定的proxy对象
	:param origin: <object: 原始model对象>
	:param proxy_class: <class: Proxy Model类>
	:return: <object: 代理对象>
	"""
	proxy = proxy_class()
	for field in origin._meta.fields:
		setattr(proxy, field.name, getattr(origin, field.name))
	return proxy


def base64_decode(content):
	"""
	解码base64字符串
	:param content: <str: base64>
	:return: <bytes>
	"""
	from base64 import b64decode

	b64content = content.split(',')[1]
	lens = len(b64content)
	padding = '=' * (( 3 - lens % 3) % 3)
	b64content += padding
	decoded_content = b64decode(b64content)
	return decoded_content
